-
Notifications
You must be signed in to change notification settings - Fork 580
feat(integration): add gen_ai.conversation.id if available
#5307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(integration): add gen_ai.conversation.id if available
#5307
Conversation
…_ai.conversation.id`
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Span Streaming
Other
Bug Fixes 🐛Google Genai
Span Streaming
Other
Internal Changes 🔧Fastmcp
Mcp
Other
🤖 This preview updates automatically when you update the PR. |
…nts-conversation-id
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.66s All tests are passing successfully. ❌ Patch coverage is 6.90%. Project has 13633 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| # Add conversation ID from agent | ||
| conv_id = getattr(agent, "_sentry_conversation_id", None) | ||
| if conv_id: | ||
| span.set_data(SPANDATA.GEN_AI_CONVERSATION_ID, conv_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated pattern for setting conversation ID on spans
Low Severity
The same 3-line pattern for extracting and setting _sentry_conversation_id from an agent onto a span is repeated 4 times across execute_tool.py, handoff.py, invoke_agent.py, and ai_client.py. This pattern should be extracted to a utility function in utils.py (e.g., _set_conversation_id(span, agent)), following the existing pattern of _set_agent_data, _set_usage_data, etc.
| origin=SPAN_ORIGIN, | ||
| ) as span: | ||
| span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "handoff") | ||
|
|
||
| # Add conversation ID from agent | ||
| conv_id = getattr(from_agent, "_sentry_conversation_id", None) | ||
| if conv_id: | ||
| span.set_data(SPANDATA.GEN_AI_CONVERSATION_ID, conv_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The _sentry_conversation_id is not propagated to the secondary agent during a handoff, causing subsequent spans from that agent to lack the conversation ID.
Severity: MEDIUM
Suggested Fix
Modify the handoff patching logic to access the secondary agent object, not just its name. Once the secondary agent instance is available, copy the _sentry_conversation_id attribute from the primary agent to the secondary agent before the handoff is executed. This will ensure that spans created by the secondary agent are correctly associated with the ongoing conversation.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/integrations/openai_agents/spans/handoff.py#L18-L25
Potential issue: During an agent handoff, the `_sentry_conversation_id` is correctly
applied to the handoff span itself but is not propagated to the secondary agent instance
that takes over the workflow. When this secondary agent subsequently runs, it does not
have the `_sentry_conversation_id` attribute set. As a result, any spans it generates
will be missing the conversation ID, because the logic relies on `getattr(agent,
"_sentry_conversation_id", None)`, which will return `None`. This breaks end-to-end
conversation tracking in multi-agent scenarios.


Description
Closes https://linear.app/getsentry/issue/TET-1721/openai-agents-add-gen-aiconversationid